#include "stdio.h"
#include "global_macros.h"
#include "huffman.h"
#include "decompress.h"
#include "compress.h"
#include "input.h"
#include "output.h"


extern void huffman_compress(char *in_filename, char *out_filename)
{

    char **codes;
    char *source;
    int occurences[ANSI_COUNT] = {0};

    codes = malloc(1);
    source = malloc(1);

    printf("reading from file...\n");
    source = read_uncompressed_file(in_filename, occurences);
    printf("building code tree...\n");
    codes = get_encoding(occurences);
    printf("writing compressed file...\n");

    write_compressed_file(out_filename, source, codes);

}

extern void huffman_decompress(char *in_filename, char *out_filename)
{
    
    char ***code_table;
    BTREE *code_tree;
    int symbol_count;
    unsigned char **source;

    code_table = malloc(1);
    source = malloc(1);

    printf("reading compressed file\n");
    symbol_count = read_compressed_file(in_filename, source, code_table);

    printf("create code tree \n");
    code_tree = recreate_tree(*code_table);

    printf("writing uncompressed file\n");
    write_uncompressed_file(out_filename, *source, code_tree, symbol_count);
}
